<div class="layui-fluid">
  <div class="layui-row">
    <div class="layui-col-xs12">
      <div class="layui-card">
        <div class="layui-card-body">
          <blockquote class="layui-elem-quote">
            把你常用的文件放到这
            <br>
            然后,一键直达~
          </blockquote>
          <fieldset class="layui-elem-field layui-field-title">
            <legend><button class='layui-btn layui-btn-normal layui-btn-sm'  onclick="createButton()">新增文件</button></legend>
          </fieldset>
          <table class="layui-table" lay-even="" lay-skin="row" style="margin-left: 45px">
          <colgroup>
          <col width="150">
          <col width="150">
          <col width="200">
          <col width="300">
          <col>
          </colgroup>
          <thead>
          <tr>
            <th>
              文件
            </th>
            <th>
              分类
            </th>
            <th>
              设定时间
            </th>
            <th>
              文件位置
            </th>
            <th>
              备注
            </th>
          </tr>
          </thead>
          <tbody id = 'linkFileHtml'>
          </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
<script src="/static/js/jquery.min.js"></script>
<link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all"/>
<script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/base64.js"></script>
<script type="text/javascript" src="/static/js/ffevent.js"></script>
<script type="text/javascript">
  var linkFileList=[]
          layui.config({
            base: '/static/plugins/layui/modules/'
        });
          layui.use(['icheck', 'laypage', 'layer'], function () {
            createButton = function () {
              var strVar = "";
                  strVar += "        <form class=\"layui-form\" method=\"post\" action=\"/linkFile/Create\" id=\"CreateLinkFileForm\">\n";
                  strVar += "                <div class=\"layui-form-item layui-form-text\">\n";
                  strVar += "                    <label class=\"layui-form-label\">按钮名称<\/label>\n";
                  strVar += "                    <div class=\"layui-input-inline\">\n";
                  strVar += "                        <input type=\"text\" placeholder=\"最多6个字哦\" name=\"BUTTONNAME\" autocomplete=\"off\" class=\"layui-input\" >\n";
                  strVar += "                    <\/div>\n";
                  strVar += "                <\/div>\n";
                  strVar += "                <div class=\"layui-form-item layui-form-text\">\n";
                  strVar += "                    <label class=\"layui-form-label\">类别<\/label>\n";
                  strVar += "                    <div class=\"layui-input-inline\">\n";
                  strVar += "                        <input type=\"text\" name=\"TYPE\" autocomplete=\"off\" class=\"layui-input\">\n";
                  strVar += "                    <\/div>\n";
                  strVar += "                <\/div>\n";
                  strVar += "                <div class=\"layui-form-item layui-form-text\">\n";
                  strVar += "                    <label class=\"layui-form-label\">文件路径<\/label>\n";
                  strVar += "                    <div class=\"layui-input-block\">\n";
                  strVar += "                        <textarea type=\"text\" name='SHELL' placeholder=\"文件路径\" class=\"layui-textarea\"><\/textarea>\n";
                  strVar += "                    <\/div>\n";
                  strVar += "                <\/div>\n";
                  strVar += "                <div class=\"layui-form-item layui-form-text\">\n";
                  strVar += "                    <label class=\"layui-form-label\">备注<\/label>\n";
                  strVar += "                    <div class=\"layui-input-block\">\n";
                  strVar += "                        <textarea type=\"text\" name='NOTE' placeholder=\"请输入备注\" class=\"layui-textarea\"><\/textarea>\n";
                  strVar += "                    <\/div>\n";
                  strVar += "                <\/div>\n";
                  strVar += "        <\/form>\n";
                  createLinkFile = window.layer.alert('创建按钮', {
                      title: '创建按钮',
                      skin: 'layui-layer-molv' //样式类名  自定义样式
                      ,
                      closeBtn: 1 // 是否显示关闭按钮
                      ,
                      anim: 0 //动画类型
                      ,
                      btn: ['创建', '取消'] //按钮
                      ,
                      content: strVar,
                      yes: function () {
                      var form = new FormData(document.getElementById("CreateLinkFileForm"));
                      $.ajax({
                          url:"/linkFile/Create",
                          type:"post",
                          data:form,
                          processData:false,
                          contentType:false,
                          success:function(data){
                            resultCode = jQuery.parseJSON(data).resultCode;
                                if (resultCode == '0') {
                                    layer.msg('创建成功');
                                    GetAllLinkFile()
                                } 
                                else{layer.alert(jQuery.parseJSON(data).result,{title:false,skin: "layui-layer-molv",area: ["250px", "150px"],time: 10000,btn:["知道了"]})}
                          }
                      });
                              window.layer.close(createLinkFile);
                          }, btn2: function () {
                              window.layer.close(createLinkFile);
                          }
                  });
            };
            GetAllLinkFile = function(){
              $.ajax({
                  url:"/linkFile",
                  type:"post",
                  success:function(data){
                    resultCode = jQuery.parseJSON(data).resultCode;
                        if (resultCode == '0') {
                            var ht = "";
                            linkFileList=jQuery.parseJSON(data).result.reverse()
                            $.each(linkFileList, function (i, item) {
                              ht+='<tr>'
                              ht+='<td><button class="layui-btn layui-btn-sm" id = '+ item[0] +' onclick="clickLinkFile()" style="width:100px">'+item[1]+'</button></td>'
                              ht+='<td>'+item[2]+'</td>'
                              ht+='<td>'+item[3]+'</td>'
                              ht+='<td> <a style="color:#1AA094" href="javascript:void(0);" onclick=\'layer.alert("文件位于：<br>'+item[5]+'",{title:false,skin: "layui-layer-molv",area: ["250px", "150px"],time: 10000,btn:["知道了"]})\'>'+item[5]+'</a></td>'
                              ht+='<td>'+item[4]+'</td>'
                              ht+='</tr>'
                            })
                            document.getElementById("linkFileHtml").innerHTML = ht;
                        } 
                        else{layer.alert(jQuery.parseJSON(data).result,{title:false,skin: "layui-layer-molv",area: ["250px", "150px"],time: 10000,btn:["知道了"]})}
                  }
              });
            };

            clickLinkFile = function(){
              BTID = event.srcElement.id;
              FileName = '';
              $.each(linkFileList, function (i, item) {
                if (item[0] == BTID){
                  FileName=item[5];
                  return false
                }
              })
                FileeEdit = layer.open({
                    type: 2,
                    title: FileName,
                    shadeClose: false,
                    shade: 0.8,
                    btn: ['保存', '删除该按钮','关闭'],
                    area: ['60%', '500px'],
                    content: '/codeEdit?filename=' + Base64.encode(FileName),
                    yes: function (index) {
                            var body = layer.getChildFrame('body', FileeEdit);
                            body.find("#codeEidtFormPostSubmit").click();
                            layer.msg('文件已提交');
                        },
                        btn2: function () {
                                            $.ajax({
                                                url:"/linkFile/Delete",
                                                type:"post",
                                                data:{
                                                  'BTID':BTID
                                                },
                                                success:function(data){
                                                  resultCode = jQuery.parseJSON(data).resultCode;
                                                      if (resultCode == '0') {
                                                          layer.msg('删除成功');
                                                          GetAllLinkFile()
                                                      } 
                                                      else{layer.alert(jQuery.parseJSON(data).result,{title:false,skin: "layui-layer-molv",area: ["250px", "150px"],time: 10000,btn:["知道了"]})}
                                                }
                                            });
                        },
                        btn3: function () {
                            layer.msg('文件关闭,未作出修改')
                        }

                });
            };



GetAllLinkFile()

          })
</script>
<style scoped>
  .site-demo-button {
    margin-bottom: 30px;
  }
  .site-demo-button div {
    margin: 20px 30px 10px;
  }
  .site-demo-button .layui-btn+.layui-btn {
    margin-left: 0;
  }
  .site-demo-button .layui-btn {
    margin: 0 7px 10px 0;
  }
  .layui-btn+.layui-btn {
    margin-left: 10px;
  }
</style>
